var width=window.screen.width;
 
var textWidth=800;
if(width>=1600){
	textWidth=1000;
 
}else if(width<=800){
	textWidth=600;;
 	
}
if (typeof HTMLElement != "undefined"
		&& !HTMLElement.prototype.insertAdjacentElement) {
	HTMLElement.prototype.insertAdjacentElement = function(where, parsedNode) {
		switch (where) {
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode, this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode, this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling)
				this.parentNode.insertBefore(parsedNode, this.nextSibling);
			else
				this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where, htmlStr) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where, parsedHTML)
	}

	HTMLElement.prototype.insertAdjacentText = function(where, txtStr) {
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where, parsedText)
	}
};
function getTextViewerWidth(){
	return textWidth;
}

function setViewerSize(textareaID){
	var viewerFrm=document.getElementById("textviewer" + textareaID);
 viewerFrm.style.height=viewerFrm.contentWindow.document.body.scrollHeight; 
alert( viewerFrm.style.height);
	
	
}



function generate_textviewer(textareaID) {

	var n = textareaID;

	var iframe = '<iframe  width="'+textWidth+'" frameborder="0"  scrolling=auto    height="100"  id="textviewer'
			+ n + '"></iframe>\n';

	document.all[n].insertAdjacentHTML("afterEnd", iframe);

	var doc = document.getElementById("textviewer" + n).contentWindow.document;
	var content = document.getElementById(n).value;
	doc.open();
	doc.write(content);
	content.contentEditable = false;
	
	doc.close();

	document.getElementById(n).style.display = 'none';


	
	 setViewerSize(textareaID);

}
